package br.ufu.facom.pillbox.dao;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class CustomSQLiteOpenHelper extends SQLiteOpenHelper {

	public static final String TABLE_AGENDA = " agenda ";
	public static final String COLUMN_ID = " id ";
	public static final String COLUMN_TM = " tm ";
	public static final String COLUMN_MEDIC = " medic ";
	public static final String COLUMN_DT_INI = " dtini ";
	public static final String COLUMN_DT_FIM = " dtfim ";
	public static final String COLUMN_DT_NOT = " dtnot ";
	public static final String COLUMN_TM_NOT = " tmnot ";
	public static final String COLUMN_TIPO = " tipo ";
	private static final String DATABASE_NAME = " medic2.db";
	
	private static final int DATABASE_VERSION = 3;
	// Database creation sql statement
	private static final String DATABASE_CREATE = 
			" create table " + TABLE_AGENDA + "("
			+ COLUMN_ID + " integer primary key autoincrement, "
			+ COLUMN_TM + " text not null, "
			+ COLUMN_MEDIC + " text not null, "
			+ COLUMN_DT_INI	+ " text not null, " 
			+ COLUMN_DT_FIM + " text not null, "
			+ COLUMN_DT_NOT	+ " text not null, "
			+ COLUMN_TM_NOT	+ " text not null, "
			+ COLUMN_TIPO + " text not null);";

	public CustomSQLiteOpenHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
		Log.d(this.getClass().getCanonicalName(), "Constructed");
	}

	@Override
	public void onCreate(SQLiteDatabase database) {
		Log.d(this.getClass().getCanonicalName(), "onCreate");
		database.execSQL(DATABASE_CREATE);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.d(this.getClass().getCanonicalName(), "onUpgrade");
		db.execSQL(" DROP TABLE IF EXISTS " + TABLE_AGENDA);
		onCreate(db);
	}

}
